#eval 剥去字符串的外衣
s1='1+3'
print(s1)
print(eval(s1))


s='{"name":"alex"}'
print(s,type(s))
print(eval(s),type(eval(s)))

#exec与eval 几乎一样，但是她是处理代码流
msg='''
for i in range(10):
    print(i)
'''
print(msg)
exec(msg)

#hash:获取一个对象(可哈希对象:int str,bool,tuple)
print(hash('fsjkdaaf'))

#help
print(help(str))

#callable是否可被调用
s1='fsdaf'
def func():
    pass
print(callable(s1))
print(callable(func))
print('*'*20)

#min max,abs：绝对值
l1=[33,2,1,54,7,-1,-9]
l2=[]
func=lambda x:abs(x)
for i in l1:
    l2.append(func(i))
print(min(l2))
print(min(l1,key=abs))
def abss(a):
    return abs(a)
print(min(l1,key=abss))
#凡是可以加key的：他会自动将可迭代对象中的每个元素按照顺序传入key对应的函数中
#按值取最大值
dic={'a':3,'b':2,'c':1}
print(min(dic))#min会默认按照字典的键去比较大小,a
def func(a):
    return dic[a]
print(min(dic,key=func))
print(min(dic, key=lambda a:dic[a]))

l2=[('太白',18),('alex',73),('wusir',35),('口天吴',41)]
print(min(l2))#('alex', 73)
print(min(l2,key=lambda a:a[-1]))
print(min(l2,key=lambda a:a[-1])[1])
#sorted
l2=[('太白',18),('alex',73),('wusir',35),('口天吴',41)]
print(dict(sorted(l2,key=lambda a:a[-1],reverse=True)))

a={"ir:0.01,w:0.01":[0,12,3,4],
   "ir:0.02,w:0.01":[7,2,8,8],
   "ir:0.03,w:0.01":[0,4,5,7],
   "ir:0.04,w:0.01":[8,25,7,6],
   "ir:0.05,w:0.01":[5,9,3,6]
   }
for i in a.items():
   print(i,'****',i[-1][1])

print(sorted(a.items(),key=lambda x:x[-1][1]))

#filter
l1=[2,3,4,5,1,6,7,8]
print([i for i in l1 if i>3])
ret=filter(lambda a:a>3,l1)#返回一个迭代器
print(ret)
print(list(ret))
#map,列表推导式的循环模式
l1=[1,4,9,16,25]
print([i**2 for i in range(1,6)])
ret=map(lambda x:x>2,range(1,6))#返回一个迭代器
print(ret)
print(list(ret))#[False, False, True, True, True]
ret=map(lambda x:x**2,range(1,6))
print(ret)
print(list(ret))

#reduce,Python 2 是内置函数，Python 3 不是，是一个模块
from functools import reduce
def func(x,y):
    '''
    第一次:x y:1 2 x+y=3
    第二次 x=3(第一次返回的3) y=3 x+y=6
    ....
    '''
    return x+y
l=reduce(func,[1,2,3,4])
print(l)
l=reduce(func,[1,2,3,4],10)
print(l)
l=reduce(lambda a,b:a+b,[1,2,3,4],10)
print(l)

# enumerate
l=['a','b','c','d']
for i in enumerate(l,1):
    print(i)